home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / strncpy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  502 b   |  30 lines

  1. #include "lib.h"
  2.  
  3. /*
  4.  * strncpy - copy at most n characters of string src to dst
  5.  */
  6. char *                /* dst */
  7. strncpy(dst, src, n)
  8. char *dst;
  9. _CONST char *src;
  10. _SIZET n;
  11. {
  12.     register char *dscan;
  13.     register _CONST char *sscan;
  14.     register _SIZET count;
  15.  
  16.     dscan = dst;
  17.     if (!(sscan = src))
  18.         sscan = "";
  19.     count = n;
  20.     while (count > 0 && (*dscan++ = *sscan++) != '\0')
  21.         count--;
  22.     while (count > 1)
  23.     {
  24.         *dscan++ = '\0';
  25.         count--;
  26.     }
  27.     *dscan = '\0';    /* make sure we terminate even when n == 0 */
  28.     return(dst);
  29. }
  30.